package com.wzdigit.wms.raw.controller.asn;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.raw.client.response.asn.AsnResponse;
import com.wzdigit.wms.raw.constant.RawWareConstant;
import com.wzdigit.wms.raw.service.asn.AsnCancleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "取消送货单")
@RequestMapping(value = RawWareConstant.API_VERSION)
public class AsnCancleController {

    public static final String REQUEST_MODEL = "/sap";

    @Autowired
    AsnCancleService asnCancleService;


    @ApiOperation(value = "SRM删改控制", notes = "SRM删改控制")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUEST_MODEL + "/asn/cancle/{asnNo}")
    public AsnResponse searchAsnHeaderReceive(
            @PathVariable("asnNo") String asnNo,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return asnCancleService.cancelAsnNo(asnNo);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;

        }
    }

}
